package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.ResourceCategoryService;
import com.yoda.mall.model.entity.ums.Resource;
import com.yoda.mall.model.entity.ums.ResourceCategory;
import com.yoda.mall.model.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("resourceCategory")
public class ResourceCategoryController {
    @Autowired
    private ResourceCategoryService resourceCategoryService;

    /**
     * 查询所有后台资源分类
     * @return
     */
    @GetMapping("listAll")
    public R<List<ResourceCategory>> listAll(){
        List<ResourceCategory> list = resourceCategoryService.listAll();
        return R.success(list);
    }

    /**
     * 添加后台资源分类
     * @param resourceCategory
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody ResourceCategory resourceCategory){
        resourceCategoryService.create(resourceCategory);
        return R.success(null);
    }

    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public R delete(@PathVariable Integer id){
        resourceCategoryService.delete(id);
        return R.success(null);
    }

    /**
     * 修改后台资源分类
     * @param id
     * @param resourceCategory
     * @return
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Integer id,@RequestBody ResourceCategory resourceCategory){
        resourceCategoryService.update(id,resourceCategory);
        return R.success(null);
    }
}
